package com.jay.composedemo.setting

import android.annotation.SuppressLint
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

/**
 * 设置界面
 */
@Composable
fun SettingsRoute(
    onBackClick: () -> Unit,
    onAboutClick: () -> Unit,
    onPrivacyClick: () -> Unit,
){
    SettingsScreen(
        onBackClick = onBackClick,
        onAboutClick = onAboutClick,
        onPrivacyClick = onPrivacyClick
    )
}

@OptIn(ExperimentalMaterial3Api::class)
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
@Composable
fun SettingsScreen(
    modifier: Modifier = Modifier,
    onBackClick: () -> Unit,
    onAboutClick: () -> Unit,
    onPrivacyClick: () -> Unit,
){
    Scaffold (
        topBar = {
            TopAppBar(
                title = {
                 Text(text = "设置")
                },
                 navigationIcon = {
                     IconButton(onClick = onBackClick) {
                         Icon(imageVector = Icons.Default.ArrowBack, contentDescription = null)
                     }
                 }
                )
        }
    ){
        paddingValues ->
        Column (
            modifier = modifier
                .padding(paddingValues)
                .fillMaxWidth()
                .verticalScroll(rememberScrollState()),
            verticalArrangement = Arrangement.spacedBy(16.dp)
         ){
          Text(
              text = "隐私政策",
              modifier= modifier
                  .fillMaxWidth()
                  .clickable {
                      onPrivacyClick()
                  }
                  .padding(horizontal = 16.dp, vertical = 8.dp)
              )
          Text(
              text = "关于",
              modifier = modifier.fillMaxWidth().clickable {
                  onAboutClick()
              }.padding(horizontal =16.dp,vertical = 8.dp)
              )
        }

    }
}